package edu.zut.cs.javaee.manager.checkwork.service.impl;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.stereotype.Service;

 
import edu.zut.cs.javaee.manager.base.service.impl.GenericManagerImpl;
 
import edu.zut.cs.javaee.manager.checkwork.dao.StudentOneDao;
import edu.zut.cs.javaee.manager.checkwork.domain.StudentOne;
import edu.zut.cs.javaee.manager.checkwork.service.StudentOneManager;

/**
 * 
 * @author 123
 **/

@Service("StudentOneManager")
@Transactional
public class StudnetManagerImpl extends GenericManagerImpl<StudentOne, Long> implements StudentOneManager {
	
	StudentOneDao studentonedao;
	
	 @Autowired
     public void setGroupDao(StudentOneDao studentonedao) {
         this.studentonedao =  studentonedao;
         this.dao = this.studentonedao;
     }

	 @Override
		public List<StudentOne> findByCode(String postcode) {

			// 创建查询条件数据对象
			StudentOne queryObject = new StudentOne();
			queryObject.setDateCreated(null);
			queryObject.setDateModified(null);
			queryObject.setCode(postcode);
			// 创建匹配器，即如何使用查询条件
			ExampleMatcher matcher = ExampleMatcher.matching() // 构建对象
					.withStringMatcher(StringMatcher.CONTAINING) // 改变默认字符串匹配方式：模糊查询
					.withIgnoreCase(true) // 改变默认大小写忽略方式：忽略大小写
					.withMatcher("postcode", GenericPropertyMatchers.startsWith()); // 地址采用“开始匹配”的方式查询
			// 创建实例并查询
			Example<StudentOne> ex = Example.of(queryObject, matcher);
			List<StudentOne> result = this.studentonedao.findAll(ex);
			return result;
		}

		@Override
		public List<StudentOne> findByFullname(String fullname) {
			// 创建查询条件数据对象
			StudentOne queryObject = new StudentOne();
			queryObject.setFullName(fullname);
			// 创建匹配器，即如何使用查询条件
			ExampleMatcher matcher = ExampleMatcher.matching() // 构建对象
					.withStringMatcher(StringMatcher.CONTAINING) // 改变默认字符串匹配方式：模糊查询
					.withMatcher("fullname", GenericPropertyMatchers.contains()) // 姓名采用“开始匹配”的方式查询
					.withIgnorePaths("dateCreated", "dateModified"); // 忽略属性：是否关注。因为是基本类型，需要忽略掉
			// 创建实例并查询
			Example<StudentOne> ex = Example.of(queryObject, matcher);
			List<StudentOne> result = this.studentonedao.findAll(ex);
			return result;
		}
             
}
